<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : system_power.manage.php   FILE_PATH : \\system\system_power.manage.php
 * 后台权限管理
 *
 * @copyright workflow_system 
 * @author  workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Tue Nov 13 17:40:45 CST 2007
 */

require_once("../global.inc.php");

class SysPowerManage extends SystemFrameWork{
	/**
	 * 权限对象
	 *
	 * @var obj
	 */
	var $obj_system_power;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	 var $obj_validate;

	 /**
	  * 部门对象
	  *
	  **/
	 var $obj_department;
	
	function main(){
		/**
		 * 创建权限对象
		 */
		if (!is_object($this->obj_system_power)){
			require_once("system_power.class.php");
			$this->obj_system_power = new SystemPowerClass();
		}
		/**
		 * 创建部门对象
		 **/
		if (!is_object($this->ojb_department))
		{
			require_once('department.class.php');
			$this->obj_department = new DepartmentClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->obj_validate)){
			require_once("commonvalidate.class.php");
			$this->obj_validate = new CommonValidate();
		}
		/**
		 * 初始化分页类
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}
		/**
		 * 语言包
		 */
		$this->getlang("system_power");

		switch ($this->_input['action']){
			case "list_group":
				$this->_list_group();
				break;
			case 'ajax_group':
				$this->_ajax_group();
				break;
			case "add_group":
				$this->_add_group();
				break;
			case "save_group":
				$this->_save_group();
				break;
			case "modi_group":
				$this->_modi_group();
				break;
			case "update_group":
				$this->_update_group();
				break;
			case "del_group":
				$this->_del_group();
				break;
///////////////////////////上组，下会员///////////////////////////////
			case "member":
				$this->_list_member();
				break;
			case "ajax_member":
				$this->_ajax_member();
				break;
			case "add_member":
				$this->_add_member();
				break;
			case "save_member":
				$this->_save_member();
				break;
			case "modi_member":
				$this->_modi_member();
				break;
			case "update_member":
				$this->_update_member();
				break;
			case "del_member":
				$this->_del_member();
				break;
			case 'move_member':
				$this->_move_member();
				break;
///////////////////////////上会员，下日志///////////////////////////////
			case "log":
				$this->_list_log();
				break;
			case "all_log":
				$this->_all_log();
				break;
			case "all_ajax_log":
				$this->_all_ajax_log();
				break;
			case "clean_log":
				$this->_clean_log();
				break;
			case "export_txt":
				$this->_export_txt();
				break;
			case "admin_password_update":
				$this->_admin_password_update();
					break;
			case 'list_department' :
				$this->list_department();
				break;
			case 'add_department' :
				$this->add_department();
				break;
			case 'save_department' :
				$this->save_department();
				break;
			case 'modi_department' :
				$this->modi_department();
				break;
			case 'update_department' :
			    $this->update_department();
			    break;
			case 'ajax_department_memeber' :
			    $this->ajax_department_memeber();
			    break;
			case 'add_fl':
			    $this->add_fl();
			    break;
			case 'add_offer':
			    $this->add_offer();
			    break;
			case 'del_department':
				$this->_del_department();
				break;
			default:
				$this->_list_group();
				break;
		}
	}

	/**
	 * 后台权限管理 首页
	 */
	function _list_group(){
		$this->_ajax_group();
	}

	/**
	 * 权限组管理
	 */
	function _ajax_group(){
		/**
		 * 获得列表
		 */
		$this->obj_page->pagebarnum(20);
		$this->obj_page->nowindex = $this->_input['curpage']?$this->_input['curpage']:1;
		$sys_group_list = $this->obj_system_power->getSystemGroupList('',$this->obj_page);
		$page_list = $this->obj_page->show(2);
		/**
		 * 页面输出
		 */
		$this->output("curpage", $this->obj_page->nowindex);
		$this->output('sys_group_list',$sys_group_list);
		$this->output('page_list',$page_list);
		$this->showpage('sys_system_power_group.list');
	}


	/**
	 * 添加权限组
	 */
	function _add_group(){
		/**
		 * 栏目列表
		 */
		$this->publicModule();
		
		/**
		 * 页面输出
		 */
		$this->showpage('sys_system_power_group.add');
	}

	/**
	 * 添加保存权限组
	 */
	function _save_group(){
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_group_name"], "require"=>"true", "message"=>$this->_lang['errSysGroupName']));
		$error = $this->obj_validate->validate();
		if($error != ""){
			$this->redirectPath('error','',$error,1);
		}
		/**
		 * 添加
		 */
		if ($this->obj_system_power->addSysGroup($this->_input)) {
			/*记录操作日志*/
			SystemPowerClass::addSysLog($this->_lang['langSystemPSetupManageNewAdd']);
			$this->redirectPath('error','./system_power.manage.php?action=list_group',$this->_lang['langSystemPNewAddGroupOk'],1);
		}else {
			$this->redirectPath('error','',$this->_lang['langCOperatorLost'],1);
		}
	}

	/**
	 * 修改权限组
	 */
	function _modi_group(){
		$sys_group_id = $this->_input['sys_group_id'];
		$group_array = $this->obj_system_power->getSysGroupById($sys_group_id);
		
		
		/**
		 * 页面输出
		 */
		$this->output("curpage", $this->_input['curpage']);
		$this->output('group_array',$group_array);
		$this->showpage('sys_system_power_group.modi');
	}

	/**
	 * 保存修改权限组
	 */
	function _update_group(){
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_group_name"], "require"=>"true", "message"=>$this->_lang['errSysGroupName']));
		$error = $this->obj_validate->validate();
		if($error != ""){
			$error = $this->formatError($error);
			$this->redirectPath('error','',$error,1);
		}

		/**
		 * 更新
		 */
		if ($this->obj_system_power->updateSysGroup($this->_input)) {
			//记录操作日志
			SystemPowerClass::addSysLog($this->_lang['langSystemPSetupManageAmend']);
			$this->redirectPath('error','./system_power.manage.php?action=list_group',$this->_lang['langSystemPAmendGroupOk'],1);
		}else {
			$this->redirectPath('error','',$this->_lang['langCOperatorLost'],1);
		}
	}

	/**
	 * 删除权限组
	 */
	function _del_group(){
		/**
		 * 判断是否权限组下还有成员
		 */
		if (is_array($this->_input['sys_group_id'])){
			//判断是否是全部删除，如果是，则返回错误，至少保留一组
			$sys_group_list = $this->obj_system_power->getSystemGroupList('',$obj_page);
			if (count($this->_input['sys_group_id']) >= count($sys_group_list)){
				$this->redirectPath('error','',$this->_lang['errSystemPGroupDelCountIsFull'],1);
			}
			foreach ($this->_input['sys_group_id'] as $value){
				$condition['sys_group_id'] = $value;
				$condition['order_group_id'] = 1;
				$sys_member_list = $this->obj_system_power->getSystemMemberList($condition,$page);
				if (!empty($sys_member_list)){
					$group_array = $this->obj_system_power->getSysGroupById($value);
					$error = $group_array['sys_group_name'].$this->_lang['langSystemPDownHaveMember']."<br/>";
					break;
				}
				unset($condition);
			}
			if ($error != ""){
				$this->redirectPath('error','',$error,1);
			}
			/**
			 * 删除权限组
			 */
			if ($this->obj_system_power->delSysGroup($this->_input['sys_group_id'])) {
				//记录操作日志
				SystemPowerClass::addSysLog($this->_lang['langSystemPSetupManageDel']);
				$this->redirectPath('error','',$this->_lang['langSystemPDelGroupOk'],1);
			}else {
				$this->redirectPath('error','',$this->_lang['langCOperatorLost'],1);
			}
		}else {
			$this->redirectPath('error','',$this->_lang['langSystemPSelectDelInfo'],1);
		}
	}

	/**
	 * 管理员列表
	 */
	function _list_member(){
		$this->_ajax_member();
	}

	/**
	 * ajax 列表页面
	 */
	function _ajax_member(){
		/**
		 * 获得列表
		 */
		$this->obj_page->pagebarnum(12);
		$this->obj_page->nowindex = $this->_input['curpage']?$this->_input['curpage']:1;
		$condition['sys_group_id'] = $this->_input['sys_group_id'];
		$condition['order_group_id'] = 1;
		$sys_member_list = $this->obj_system_power->getSystemMemberList($condition,$this->obj_page);
		if ($this->_input['sys_group_id'] !='' ){
			/*取权限组名称*/
			$group_array = $this->obj_system_power->getSysGroupById($this->_input['sys_group_id']);
			if (is_array($sys_member_list)){
				foreach ($sys_member_list as $k => $v){
					$sys_member_list[$k]['sys_group_name'] = $group_array['sys_group_name'];
				}
			}
			unset($group_array);
		}else {
			if (is_array($sys_member_list)){
				foreach ($sys_member_list as $k => $v){
					$array = $this->obj_system_power->getSysGroupById($v['sys_group_id']);
					$sys_member_list[$k]['sys_group_name'] = $array['sys_group_name'];
					unset($array);
				}
			}
		}
		$page_list = $this->obj_page->show(2);
		if ($this->obj_page->nowindex == ''){
			$this->obj_page->nowindex = 1;
		}
		//权限组列表
		$group_array = $this->obj_system_power->getSystemGroupList('',$obj_page);
		/**
		 * 页面输出
		 */
		$this->output("curpage", $this->obj_page->nowindex);
		$this->output('sys_member_list',$sys_member_list);
		$this->output('page_list',$page_list);
		$this->output('group_array',$group_array);
		$this->output('sys_group_id',$this->_input['sys_group_id']);
		$this->showpage('sys_system_power_member.list');
	}

	/**
	 * 添加管理员
	 */
	function _add_member(){
		
	}

	/**
	 * 保存添加管理员
	 */
	function _save_member(){
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_login_name"], "require"=>"true", "message"=>$this->_lang['errMloginname']),
		array("input"=>$this->_input["sys_login_name"], "validator"=>"Length", "min"=>"5", "max"=>"20", "message"=>$this->_lang['errWrongUserName']),
		array("input"=>$this->_input["sys_login_name"], "validator"=>"Length", "min"=>"5", "max"=>"20", "message"=>$this->_lang['errWrongUserName']),
		array("input"=>$this->_input["sys_password"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
		array("input"=>$this->_input["sys_password_two"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
		array("input"=>$this->_input["sys_password"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
		array("input"=>$this->_input["sys_password_two"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
		array("input"=>$this->_input["sys_password"], "require"=>"true", "validator"=>"Compare", "operator"=>"==","to"=>$this->_input["sys_password_two"], "message"=>$this->_lang['errMmatchingpassword'],"result"=>true),
		array("input"=>$this->_input['sys_email'],"require"=>"true","validator"=>"Email","message"=>$this->_lang['errEmail'])
		);
		$error = $this->obj_validate->validate();
		if($error != ""){
			$this->redirectPath('error','',$error,1);
		}
		//验证会员名是否重复
		$condition['sys_login_name'] = $this->_input['sys_login_name'];
		$member_list = $this->obj_system_power->getSystemMemberList($condition,$page);
		if (!empty($member_list)){
			$this->redirectPath('error','',$this->_lang['langSystemPMemberIsExists'],1);
		}
		/**
		 * 添加管理员
		 */
		if ($this->obj_system_power->addSysMember($this->_input)) {
			//记录操作日志
			SystemPowerClass::addSysLog($this->_lang['langSystemPSetupManageAddAdmin']);
			$this->redirectPath('error','./system_power.manage.php?action=ajax_member',$this->_lang['langSystemPAddAdminOk'],1);
		}else {
			$this->redirectPath('error','',$this->_lang['langCOperatorLost'],1);
		}
	}

	/**
	 * 修改管理员
	 */
	function _modi_member(){
		/**
		 * 取管理员信息
		 */
		$sys_member_id = $this->_input['sys_member_id'];
		$member_array = $this->obj_system_power->getSysMemberById($sys_member_id);
		/**
		 * 权限组列表
		 */
		$sys_group_list = $this->obj_system_power->getSystemGroupList('',$page);
		/**
		 * 页面输出
		 */
		$this->output('member_array',$member_array);
		$this->output('sys_group_list',$sys_group_list);
		$this->showpage('sys_system_power_member.modi');
	}

	/**
	 * 保存更新管理员
	 */
	function _update_member(){

		/**
		 * 验证接收变量
		 */
		if ($this->_input["sys_password"] != "" || $this->_input["sys_password_two"] != ""){
			$this->obj_validate->setValidate(array("input"=>$this->_input['sys_password'],"require"=>"true","message"=>$this->_lang['errMpassword']));
			$this->obj_validate->setValidate(array("input"=>$this->_input['sys_password_two'],"require"=>"true","message"=>$this->_lang['errMpassword']));
			$this->obj_validate->setValidate(array("input"=>$this->_input['sys_password'],"validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']));
			$this->obj_validate->setValidate(array("input"=>$this->_input["sys_password_two"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']));
			$this->obj_validate->setValidate(array("input"=>$this->_input["sys_password"], "require"=>"true", "validator"=>"Compare", "operator"=>"==","to"=>$this->_input["sys_password_two"], "message"=>$this->_lang['errMmatchingpassword'],"result"=>true));
		}
		$this->obj_validate->setValidate(array("input"=>$this->_input['sys_email'],"require"=>"true","validator"=>"Email","message"=>$this->_lang['errEmail']));
		$error = $this->obj_validate->validate();
		if($error != ""){
			$this->redirectPath('error','',$error,1);
		}
		/**
		 * 更新
		 */
		if ($this->obj_system_power->updateSysMember($this->_input)) {
			//记录操作日志
			SystemPowerClass::addSysLog($this->_lang['langSystemPSetupManageAmendAdmin']);
			$this->redirectPath('error','./system_power.manage.php?action=ajax_member',$this->_lang['langSystemPAmendAdminOk'],1);
		}else {
			$this->redirectPath('error','',$this->_lang['langCOperatorLost'],1);
		}
	}

	/**
	 * 删除管理员
	 */
	function _del_member(){
		if (is_array($this->_input['sys_member_id'])){
			//判断删除数量是否是全部管理员，如果是，则返回错误
			$sys_member_list = $this->obj_system_power->getSystemMemberList('',$page);
			if (count($this->_input['sys_member_id']) >= count($sys_member_list)){
				$this->redirectPath('error','',$this->_lang['errSystemPAdminDelCountIsFull'],1);
			}
			if ($this->obj_system_power->delSysMember($this->_input['sys_member_id'])) {
				//记录操作日志
				SystemPowerClass::addSysLog($this->_lang['langSystemPSetupManageDeleteAdmin']);
				$this->redirectPath('error','./system_power.manage.php?action=ajax_member',$this->_lang['langSystemPDeleteAdminOk'],1);
			}else {
				$this->redirectPath('error','',$this->_lang['langCOperatorLost'],1);
			}
		}else {
			$this->redirectPath('error','',$this->_lang['langSystemPSelectDelInfo'],1);
		}
	}
	
	/**
	 * 转移管理员用户组
	 */
	function _move_member(){
		/**
		 * 信息验证
		 */
		$this->obj_validate->validateparam = array(
			array("input"=>$this->_input["sys_member_id"], "require"=>"true", "message"=>$this->_lang['langSystemPAdminMoveIsEmpty']),
			array("input"=>$this->_input["move_group_id"], "require"=>"true","validator"=>"Number", "message"=>$this->_lang['langSystemPAdminMoveGroupIsEmpty'])
		);
		$error = $this->obj_validate->validate();
		if ($error != ''){
			$this->redirectPath('error','',$error,1);
		}else {
			if (!empty($this->_input["sys_member_id"])){
				//将删除数组的信息转移到选择的类别中
				$this->obj_system_power->moveMemberToGroup($this->_input["sys_member_id"],$this->_input["move_group_id"]);
				$this->redirectPath('error','',$this->_lang['langSystemPAdminMoveSucc'],1);
			}else {
				$this->redirectPath('error','',$this->_lang['errSystemPAdminMoveIsFaild'],1);
			}
		}
		
	}
	
	/**
	 * 添加管理日志
	 */
	function _add_log($log){
		$this->obj_system_power->addSysLog($this->_input);
	}

	/**
	 * 管理员日志
	 */
	function _list_log(){
		//获取管理员列表
		
		
		/**
		 * 获得列表
		 */
		$this->obj_page->pagebarnum(15);
		//时间
		
		
		if ($this->_input['sys_member_id'] != ""){
			$condition['sys_member_id'] = $this->_input['sys_member_id'];
		}
		$condition['order_log_id'] = 1;
		$sys_log_list = $this->obj_system_power->listSysLog($condition,$this->obj_page);
		$page_list = $this->obj_page->show(2);
		if (is_array($sys_log_list)){
			foreach ($sys_log_list as $k => $v){
				$sys_log_list[$k]['sys_log_time'] = @date("Y-m-d H:i",$v['sys_log_time']);
			}
		}
		/**
		 * 页面输出
		 */
		$this->output('page_list',$page_list);
		$this->output('sys_log_list',$sys_log_list);
		$this->showpage('sys_system_log.list');
	}

	/**
	 * 管理员日志_全部
	 */
	function _all_log(){
		$this->_all_ajax_log();
	}

	/**
	 * 管理日志全部 ajax列表
	 */
	function _all_ajax_log(){
		/**
		 * 获得列表
		 */
		$this->obj_page->pagebarnum(15);
		if ($this->_input['sys_member_id'] != ""){
			$condition['sys_member_id'] = $this->_input['sys_member_id'];
		}
		$condition['order_log_id'] = 1;
		$sys_log_list = $this->obj_system_power->listSysLog($condition,$this->obj_page);
		$page_list = $this->obj_page->show(2);

		if (is_array($sys_log_list)){
			foreach ($sys_log_list as $k => $v){
				$sys_log_list[$k]['sys_log_time'] = @date("Y-m-d H:i",$v['sys_log_time']);
			}
		}
		
		/**
		 * 页面输出
		 */
		$this->output('page_list',$page_list);
		$this->output('sys_log_list',$sys_log_list);
		$this->showpage('sys_system_log.list');
	}

	/**
	 * 清空
	 */
	function _clean_log(){
//		if ($this->obj_system_power->clean_log()) {
//			//记录操作日志
//			SystemPowerClass::addSysLog($this->_lang['langSystemPLogClean']);
//			Common::outMessage("json",$this->_lang['langSystemPConfirmDelLogOk'],1);
//			exit;
//		}else {
//			Common::outMessage("json",$this->_lang['langCOperatorLost'],0);
//		}
	}

	/**
	 * 导出为TXT格式
	 */
	function _export_txt(){
		$condition['order_log_id'] = 1;
		$sys_log_list = $this->obj_system_power->listSysLog($condition,$page);
		if (is_array($sys_log_list)){
			foreach ($sys_log_list as $k => $v){
				$line .= date('Y-m-d H:i:s',$v['sys_log_time']);
				$line .= "	";
				$line .= $v['sys_login_name'];
				$line .= "	";
				$line .= $v['sys_log_note'];
				$line .= "	";
				$line .= "\r\n";
			}
		}
		
		include("zip.class.php");
		header("Content-type:application/x-zip");
		header("Content-Disposition:   attachment;   filename=log.zip");
		$zipfile   =   new   zipfile();
		$zipfile   ->   addFile($line,'log.txt');
		$out   =   $zipfile   ->   file();
		echo   $out;
	}
	
	/**
	 * 管理员修改自己密码
	 */
	function _admin_password_update(){
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["password"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
		array("input"=>$this->_input["password2"], "require"=>"true", "message"=>$this->_lang['errMpassword']),
		array("input"=>$this->_input["password"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
		array("input"=>$this->_input["password2"], "validator"=>"Length", "min"=>"5", "max"=>"16", "message"=>$this->_lang['errWrongPassword']),
		array("input"=>$this->_input["password"], "require"=>"true", "validator"=>"Compare", "operator"=>"==","to"=>$this->_input["password2"], "message"=>$this->_lang['errMmatchingpassword'],"result"=>true),
		);
		$error = $this->obj_validate->validate();
		if($error != ""){
			$this->redirectPath('error','',$error,1);
		}
		/*取管理员信息*/
		$admin_array = $this->obj_system_power->getSysMemberById($_SESSION['s_admin']['id']);
		$admin_array['sys_password'];
		if (md5($this->_input['password_old']) != $admin_array['sys_password']){
			$this->redirectPath('error','',$this->_lang['errMOldPassErr'],1);
		}else {
			$this->_input['sys_member_id'] = $admin_array['sys_member_id'];
			$this->_input['sys_group_id'] = $admin_array['sys_group_id'];
			$this->_input['sys_password'] = $this->_input['password'];
			$result = $this->obj_system_power->updateSysMember($this->_input);
			if ($result == true) {
				//修改SESSION中的旧密码
				$_SESSION['s_admin']['password'] = md5($this->_input['sys_password']);
				//记录操作日志
				SystemPowerClass::addSysLog($this->_lang['langSystemPLogUpdateAdminPassword']);
				$this->redirectPath('error','index.php?action=index_info',$this->_lang['langSystemPPassAmendOk'],1);
			}else {
				$this->redirectPath('error','',$this->_lang['langCOperatorLost'],1);
			}
		}
	}

	/*
	 * 添加部门
	 **/
	public function add_department()
	{
		$department_list = $this->obj_department->getDepartmentList(array('parent_id' => 0), $page);

		$this->output('department_list', $department_list);
		$this->showpage('sys_system_department.add');
	}

	/* 
	 * 保存部门数据
	 *
	 **/
	public function save_department()
	{
		/**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_department_name"], "require"=>"true", "message"=>'请输入部门名称'));
		$error = $this->obj_validate->validate();
		if($error != ""){
			$this->redirectPath('error','',$error,1);
		}
		/**
		 * 添加
		 */
		if ($this->obj_department->addDepartment($this->_input)) {
			/*记录操作日志*/
			SystemPowerClass::addSysLog('添加部门' . $_input['sys_department_name']);
			$this->redirectPath('error','./system_power.manage.php?action=list_department', '添加部门成功', 1);
		}else {
			$this->redirectPath('error','', '添加失败', 1);
		}
	}

	/**
	 * 部门信息列表
	 **/
	public function list_department()
	{
		/**
		 * 获得列表
		 */
		$this->obj_page->pagebarnum(20);
		$this->obj_page->nowindex = $this->_input['curpage']?$this->_input['curpage']:1;
		$sys_department_list = $this->obj_department->getDepartmentList('',$this->obj_page);
		$page_list = $this->obj_page->show(2);
		/**
		 * 页面输出
		 */
		$this->output("curpage", $this->obj_page->nowindex);
		$this->output('sys_department_list',$sys_department_list);
		$this->output('page_list',$page_list);
		$this->showpage('sys_system_department.list');
	}

	/* 修改部门信息 */
	public function modi_department()
	{
	    $department_id = $this->_input['id'];
		$department_info = $this->obj_department->getDepartmentById($department_id);
		$department_list = $this->obj_department->getDepartmentList(array('parent_id' => 0), $page);

		/**
		 * 页面输出
		 */
		$this->output("curpage", $this->_input['curpage']);
		$this->output('department_list', $department_list);
		$this->output('department_info', $department_info);
		$this->showpage('sys_system_department.modi');
	}
	
	/* 
	 * 保存更新信息
	 *
	 **/
	public function update_department()
	{
	    /**
		 * 验证接收变量
		 */
		$this->obj_validate->validateparam = array(
		array("input"=>$this->_input["sys_department_name"], "require"=>"true", "message"=>'请填写部门名称'));
		$error = $this->obj_validate->validate();
		if($error != ""){
			$error = $this->formatError($error);
			$this->redirectPath('error','',$error,1);
		}

		/**
		 * 更新
		 */
		if ($this->obj_department->updateDepartment($this->_input)) {
			//记录操作日志
			SystemPowerClass::addSysLog('更新部门信息');
			$this->redirectPath('error','./system_power.manage.php?action=list_department','更新部门信息成功',1);
		}else {
			$this->redirectPath('error','','更新部门信息失败',1);
		}
	}
	/**
	 * 删除部门
	 *
	 */
	public function _del_department()
	{
		/**
		 * 判断是否权限组下还有成员
		 */
		if (is_array($this->_input['sys_department_id'])){
			$this->obj_department->delDepartment($this->_input['sys_department_id']);
			$this->redirectPath('error','./system_power.manage.php?action=list_department','删除部门信息成功',1);
		}
		else
		{
			$this->redirectPath('error','./system_power.manage.php?action=list_department','删除部门信息失败',1);
		}
	}
	/*
	 * 部门员工列表
	 **/
	public function ajax_department_memeber()
	{

	}
	
	public function add_fl()
	{
	    $this->showpage('sys_system_mem.add_fl');
	}
	
	public function add_offer()
	{
	    $this->showpage('sys_system_mem.add_offer');
	}
}

$system_power = new SysPowerManage();
$system_power->main();
unset($system_power);
?>